Skip to content

feat: gather async deps concurrently with asyncio.gather + pending sentinel#705

Closed
FRidh wants to merge 1 commit intoreagento:developfrom
FRidh:feat/async-concurrent-resolution-a
Closed

feat: gather async deps concurrently with asyncio.gather + pending sentinel#705
FRidh wants to merge 1 commit intoreagento:developfrom
FRidh:feat/async-concurrent-resolution-a

Conversation

@FRidh
Copy link
Copy Markdown

@FRidh FRidh commented Apr 3, 2026

When resolving an async factory with 2+ async dependencies, the compiled
getter now awaits them concurrently via asyncio.gather instead of
sequentially. For N independent deps each taking T seconds, resolution
takes max(T) instead of sum(T). No user-side changes are required.

This is implemented as a compile-time code generation change: the
compiled factory function is generated with asyncio.gather instead of
sequential inline awaits. The cache dict semantics and CompiledFactory
protocol are unchanged, and the sync container is unaffected.

Diamond patterns (A→C, B→C) are handled via a _Pending Future sentinel:
the first coroutine to resolve a cached dep places a sentinel in the
cache; concurrent coroutines await it instead of duplicating work and
registering duplicate exits. Uncached (cache=False) shared deps are also
safe to gather since each branch creates its own independent instance.

#45

@FRidh FRidh force-pushed the feat/async-concurrent-resolution-a branch from c273482 to c3c4044 Compare April 3, 2026 08:15
…ntinel

When resolving an async factory with 2+ async dependencies, the compiled
getter now awaits them concurrently via asyncio.gather instead of
sequentially. For N independent deps each taking T seconds, resolution
takes max(T) instead of sum(T). No user-side changes are required.

This is implemented as a compile-time code generation change: the
compiled factory function is generated with asyncio.gather instead of
sequential inline awaits. The cache dict semantics and CompiledFactory
protocol are unchanged, and the sync container is unaffected.

Diamond patterns (A→C, B→C) are handled via a _Pending Future sentinel:
the first coroutine to resolve a cached dep places a sentinel in the
cache; concurrent coroutines await it instead of duplicating work and
registering duplicate exits. Uncached (cache=False) shared deps are also
safe to gather since each branch creates its own independent instance.

reagento#45
@FRidh FRidh force-pushed the feat/async-concurrent-resolution-a branch from c3c4044 to 3b0f09a Compare April 3, 2026 08:20
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 3, 2026

@Tishka17
Copy link
Copy Markdown
Member

Tishka17 commented Apr 3, 2026

I am a bit worried because you made commits almost simultaneously on two PRs. Did you write this code?

@FRidh
Copy link
Copy Markdown
Author

FRidh commented Apr 5, 2026

Closing this POC, discussion in #45.

@FRidh FRidh closed this Apr 5, 2026
@github-project-automation github-project-automation bot moved this to To be released in Dishka kanban Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To be released

Development

Successfully merging this pull request may close these issues.

2 participants